using UnityEngine;

public class CollisionSenses : CoreComponent, ILogicupdateable
{
    [SerializeField] private Vector2 _ceilingCheckSize;
    [SerializeField] private Vector2 _groundCheckSize;
    [SerializeField] private float _wallCheckDistance;
    [SerializeField] private LayerMask _whatIsGround;


    protected override void Awake()
    {
        base.Awake();

        core.AddCoreComponent(this);
    }

    void ILogicupdateable.LogicUpdate()
    {
    }

    #region Check Tranform

    public Vector2 CeilingCheckSize
    {
        get => _ceilingCheckSize;
        set => _ceilingCheckSize = value;
    }

    public Vector2 GroundCheckSize
    {
        get => _groundCheckSize;
        set => _groundCheckSize = value;
    }

    public float WallCheckDistance
    {
        get => _wallCheckDistance;
        set => _wallCheckDistance = value;
    }

    public LayerMask WhatIsGround
    {
        get => _whatIsGround;
        set => _whatIsGround = value;
    }

    public Transform GroundCheck
    {
        get => GenericNotImplementError<Transform>.TryGet(_groundCheck, core.transform.parent.name);
        private set => _groundCheck = value;
    }

    public Transform WallCheck
    {
        get => GenericNotImplementError<Transform>.TryGet(_wallCheck, core.transform.parent.name);
        private set => _wallCheck = value;
    }

    public Transform LedgeCheckHorizontal
    {
        get => GenericNotImplementError<Transform>.TryGet(_ledgeCheckHorizontal, core.transform.parent.name);
        private set => _ledgeCheckHorizontal = value;
    }

    public Transform LedgeCheckVertical
    {
        get => GenericNotImplementError<Transform>.TryGet(_ledgeCheckVertical, core.transform.parent.name);
        private set => _ledgeCheckVertical = value;
    }

    public Transform CeilingCheck
    {
        get => GenericNotImplementError<Transform>.TryGet(_ceilingCheck, core.transform.parent.name);
        private set => _ceilingCheck = value;
    }

    [SerializeField] private Transform _groundCheck;
    [SerializeField] private Transform _wallCheck;
    [SerializeField] private Transform _ledgeCheckHorizontal;
    [SerializeField] private Transform _ledgeCheckVertical;
    [SerializeField] private Transform _ceilingCheck;

    #endregion

    #region Check Functions

    public bool Ceiling =>
        //get => Physics2D.OverlapCircle(_ceilingCheck.position, _playerData._ceilingCheckRadius, _playerData._whatIsGround);
        Physics2D.OverlapBox(CeilingCheck.position, _ceilingCheckSize, 0f, _whatIsGround);

    public bool Grounded =>
        //get => Physics2D.OverlapCircle(_groundCheck.position, _playerData._groundCheckRadius, _playerData._whatIsGround);
        Physics2D.OverlapBox(GroundCheck.position, _groundCheckSize, 0f, _whatIsGround);

    public bool WallFront => Physics2D.Raycast(WallCheck.position, Vector2.right * core.Movement.FacingDirection,
        _wallCheckDistance, _whatIsGround);

    //Color color = hit ? Color.red : Color.green;
    //Debug.DrawRay(_wallCheck.transform.position, _playerData._wallCheckDistance * new Vector2(FacingDirection, 0), color);
    public bool WallBack => Physics2D.Raycast(WallCheck.position, Vector2.right * -core.Movement.FacingDirection,
        _wallCheckDistance, _whatIsGround);

    public bool LedgeHorizontal => Physics2D.Raycast(LedgeCheckHorizontal.position,
        Vector2.right * core.Movement.FacingDirection, _wallCheckDistance, _whatIsGround);

    public bool LedgeVertical =>
        Physics2D.Raycast(LedgeCheckVertical.position, Vector2.down, _wallCheckDistance, _whatIsGround);

    #endregion
}